#pragma once
#include "common.h"
#include "CSocketClient.h"
#include "CThreadPool.h"
using namespace std;

class CSocketClientManager
{
	friend unsigned __stdcall _ThreadProcSocketClient(void* arg);
protected:
	CThreadPool m_tpHandlePool;
	list<CSocketClient*> m_lstSocketClient;
	bool m_bClose;
	CRITICAL_SECTION m_csLock;
protected:
	bool AddSocketClient(CSocketClient*);
	bool RemoveSocketClient(CSocketClient*);
	bool HandleSocketProc(SOCKETDESOBJ socketDesObj, PSOCKETOBJ pSocketObj, HANDLE hThread);

	virtual bool GetSocketClientType(SOCKETDESOBJ& socketDesObj, PSOCKETOBJ pSocketObj, void* selectParam);
	virtual bool OnAcceptSocketClient(CSocketClient* pSocketClient, int type, int id);
	virtual void OnDiscardSocketClient(CSocketClient* pSocketClient, int type, int id);
public:
	CSocketClientManager();
	bool StartSocketClientThread(PSOCKETOBJ pSocketObj, void* selectParam, bool bAutoReleaseThread);
	virtual void CloseAllServer();
	virtual void CloseSocketClient(CSocketClient*);
};

